-- set_console
--
local trace = trace
local import = import
local main_ctx = main_ctx
---@type behavior_ret
local bret = import("bt/bt_plugin/behavior3/behavior_ret")

local M = {
    name = "set_console",
    type = "Action",
    desc = "设置控制台",
    args = {
        { "isSetConsoleState", "boolean?", "是否设置状态" },
        { "consoleState", "int?", "状态" },
        { "isSetEndGame", "boolean?", "是否设置游戏结束" },
        { "halfDaySwitch", "boolean?", "0.5天完成时间" },
    },
}

local status = {
    [0] = "正常",
    [1] = "完成",
    [2] = "封禁",
}

function M.run(node, env, value)
    local isSetConsoleState = node.args.isSetConsoleState
    local consoleState = node.args.consoleState
    local isSetEndGame = node.args.isSetEndGame
    local halfDaySwitch = node.args.halfDaySwitch or false
    if isSetConsoleState and consoleState then
        local str = string.format("控制台标志状态:%s", status[consoleState])
        trace.log_trace(str)
        local time = os.time()
        local lastTime = os.time() - 43200
        if halfDaySwitch then
            main_ctx:set_ex_state_ex(consoleState, lastTime)
        else
            main_ctx:set_ex_state_ex(consoleState, time)
        end
    end

    if isSetEndGame then
        trace.log_trace('执行下线')
        main_ctx:end_game()
    end
    return bret.SUCCESS
end

return M

